package net.esj.basic.plugins.struts2;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import net.esj.basic.core.utils.FileItem;

import com.opensymphony.xwork2.ActionContext;

public abstract class Struts2Utils {

	public static Map<String,FileItem> analyzFile(ActionContext actionContext){
		Map<String,FileItem> map = new HashMap<String, FileItem>();
		Map<String,Object> params = actionContext.getParameters();
		for(Map.Entry<String, Object> entry : params.entrySet()){
			if(entry.getValue() instanceof File[]){
				File[] file = (File[]) entry.getValue();
				String filekey = entry.getKey();
				String[] fileName = (String[])params.get(filekey+"FileName");
				String[] contextType = (String[])params.get(filekey+"ContentType");
				FileItem item = new FileItem();
				item.setFile(file);
				item.setContextType(contextType);
				item.setFileName(fileName);
				map.put(filekey, item);
			}
		}
		
		return map;
	}
}
